home *** CD-ROM | disk | FTP | other *** search
- DECLARE SUB SelectField (ColSpace%, ColWidth%, DispArray$(), Msg$, MsgRow%, NumCols%, NumSelections%, NumRows%, Selection%, StartCol%, StartRow%, Title$, TitleRow%)
- DECLARE SUB DisplayScreen (ColSpace%, ColWidth%, Msg$, MsgRow%, NumCols%, NumRows%, NumSelections%, RowOffSet%, StartCol%, Title$, TitleRow%)
-
- 'dim to total # of fields
- DIM SHARED DispArray$(48)
- COMMON SHARED ForeNorm%, BackNorm%, ForeHi%, BackHi%
-
- 'NOTE: it is your responsibility to layout the screen in such
- 'a way so as to prevent wraparound...selectfield does not do
- 'any checking for this-make sure that your screens are
- 'rectanguar or square (every column has same # of rows and every
- 'row has same # of columns) and that they will fit into an 80 x 24 space
- NumRows% = 12 'number of lines per column
- NumCols% = 4 'number of columns per line
- NumSelections% = NumRows% * NumCols%
- ColWidth% = 8 'width of each column(field)
- ColSpace% = 12 'spacing between columns
- StartRow% = 5 'row # for first field
- StartCol% = 6 'col # for first field-adjust to center the display
- Title$ = " USER SELECTION TEST "
- TitleRow% = 2
- Msg$ = " Use Arrows,TAB,HOME or END To Move Highlight Bar, <ENTER> To Make Selection "
- MsgRow% = 22
-
- 'normal colors
- ForeNorm% = 3
- BackNorm% = 0
- 'highlight colors
- ForeHi% = 4
- BackHi% = 7
-
- 'assign the desired display options to display string array-can
- 'do it in a for next loop, or READ/DATA statements, etc
- DispArray$(1) = "CHOICE01"
- DispArray$(2) = "CHOICE02"
- DispArray$(3) = "CHOICE03"
- DispArray$(4) = "CHOICE04"
- DispArray$(5) = "CHOICE05"
- DispArray$(6) = "CHOICE06"
- DispArray$(7) = "CHOICE07"
- DispArray$(8) = "CHOICE08"
- DispArray$(9) = "CHOICE09"
- DispArray$(10) = "CHOICE10"
- DispArray$(11) = "CHOICE11"
- DispArray$(12) = "CHOICE12"
- DispArray$(13) = "CHOICE13"
- DispArray$(14) = "CHOICE14"
- DispArray$(15) = "CHOICE15"
- DispArray$(16) = "CHOICE16"
- DispArray$(17) = "CHOICE17"
- DispArray$(18) = "CHOICE18"
- DispArray$(19) = "CHOICE19"
- DispArray$(20) = "CHOICE20"
- DispArray$(21) = "CHOICE21"
- DispArray$(22) = "CHOICE22"
- DispArray$(23) = "CHOICE23"
- DispArray$(24) = "CHOICE24"
- DispArray$(25) = "CHOICE25"
- DispArray$(26) = "CHOICE26"
- DispArray$(27) = "CHOICE27"
- DispArray$(28) = "CHOICE28"
- DispArray$(29) = "CHOICE29"
- DispArray$(30) = "CHOICE30"
- DispArray$(31) = "CHOICE31"
- DispArray$(32) = "CHOICE32"
- DispArray$(33) = "CHOICE33"
- DispArray$(34) = "CHOICE34"
- DispArray$(35) = "CHOICE35"
- DispArray$(36) = "CHOICE36"
- DispArray$(37) = "CHOICE37"
- DispArray$(38) = "CHOICE38"
- DispArray$(39) = "CHOICE39"
- DispArray$(40) = "CHOICE40"
- DispArray$(41) = "CHOICE41"
- DispArray$(42) = "CHOICE42"
- DispArray$(43) = "CHOICE43"
- DispArray$(44) = "CHOICE44"
- DispArray$(45) = "CHOICE45"
- DispArray$(46) = "CHOICE46"
- DispArray$(47) = "CHOICE47"
- DispArray$(48) = "CHOICE48"
-
- 'call routine to display choices and get user selection
- CALL SelectField(ColSpace%, ColWidth%, DispArray$(), Msg$, MsgRow%, NumCols%, NumSelections%, NumRows%, Selection%, StartCol%, StartRow%, Title$, TitleRow%)
- COLOR ForeNorm%, BackNorm%, 0
- CLS
- 'assign user selection and description string
- UserChoice% = Selection%
- 'print choice
- PRINT "Your Selection Was "; DispArray$(UserChoice%)
-
- END
-
- SUB DisplayScreen (ColSpace%, ColWidth%, Msg$, MsgRow%, NumCols%, NumRows%, NumSelections%, RowOffSet%, StartCol%, Title$, TitleRow%)
- '
- '----------------------------------------------------------------------------
- ' Input : Number of rows to be displayed in NumRows%, number of columns
- ' in NumCols%, starting column # in StartCol%, string array
- ' containing selection strings to display in DispArray(x)
- ' (shared array), number of selections to display in
- ' NumSelections%, spacing between columns in ColSpace%, width of
- ' each column in ColWidth%, message to display in Msg$, row on
- ' which to display message in MsgRow%, color numbers in ForeHi%
- ' and BackHi% (shared scalars)
- ' Process : Displays the selections and user message
- ' Output : User selection in Selection%
- ' Coupling : Called by SelectField
- ' Calls no subs or functions
- '
- '----------------------------------------------------------------------------
- '
-
- 'display the selector screen & highlight initial choice
- FOR I% = 1 TO (NumSelections% / NumCols%)
- 'col 2 gets us inside the left side of the border (if one)
- LOCATE I% + RowOffSet%, StartCol%
-
- 'assign current ctr val-will inc by number of rows
- Ctr% = I%
-
- FOR ColCtr% = 1 TO NumCols%
-
- 'calculate value for TAB function which follows
- A = ((((ColCtr% - 1) * ColWidth%) + StartCol%) + (ColCtr% - 1) * ColSpace%)
- PRINT TAB(A); DispArray$(Ctr%);
- Ctr% = Ctr% + NumRows%
-
- NEXT ColCtr%
-
- 'done displaying line-go to next line
- PRINT
-
- NEXT I%
-
- COLOR ForeHi%, BackHi%, 0
-
- LOCATE TitleRow%, ((80 - LEN(Title$)) / 2)
- PRINT Title$
- 'print message line
- LOCATE MsgRow%, 3
- PRINT Msg$
-
- END SUB
-
- SUB SelectField (ColSpace%, ColWidth%, DispArray$(), Msg$, MsgRow%, NumCols%, NumSelections%, NumRows%, Selection%, StartCol%, StartRow%, Title$, TitleRow%)
- '
- '----------------------------------------------------------------------------
- ' Input : Number of rows to be displayed in NumRows%, number of columns
- ' in NumCols%, width of each column in ColWidth%, starting line
- ' number in StartRow%, starting column # in StartCol%, string
- ' array containing selection strings to display in DispArray(x),
- ' number of selections to display in NumSelections%, spacing
- ' between columns in ColSpace%, message to display in Msg$, row
- ' on which to display message in MsgRow%
- ' Process : Allows user to cycle thru all possible selections displayed
- ' until carriage return is pressed.
- ' Output : User selection in Selection%
- ' Coupling : Called by Main
- ' Calls DisplayScreen
- '
- '----------------------------------------------------------------------------
- '
- ' Define names similar to keyboard names with their equivalent key codes.
- ENTER = 13
- RIGHTAB = 9
- LEFTAB = 15
- DNARROW = 80
- UPARROW = 72
- LEFT = 75
- RIGHT = 77
- HOME = 71
- ENDK = 79
- PGDN = 81
- PGUP = 73
-
- RowOffSet% = StartRow% - 1
- ' Set the row and column index ptrs to 1,1
- Row% = 1
- Col% = 1
- 'set initial selection # to 1
- Selection% = 1
-
- 'display whole screen in normal colors
- COLOR ForeNorm%, BackNorm%, 0
- CLS
-
- CALL DisplayScreen(ColSpace%, ColWidth%, Msg$, MsgRow%, NumCols%, NumRows%, NumSelections%, RowOffSet%, StartCol%, Title$, TitleRow%)
-
- 'we will high lite 1st selection when menu comes up, row 1 col 1
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
- '
-
- 'Top of "Do <Get User Selection> Until User Hits Enter Key" loop
- DO
- 'Top of "Do <Get Key> Until User Hits a Key" loop
- DO
-
- Ky$ = INKEY$
- 'can't do ASC fn on zero, so trap zero
- IF LEN(Ky$) > 0 THEN
- Ky% = ASC(RIGHT$(Ky$, 1))
- END IF
-
- LOOP UNTIL LEN(Ky$) > 0
-
- SELECT CASE Ky%
-
- '**************** DOWN ARROW PRESSED ********************
-
- CASE IS = DNARROW
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
-
- GOSUB NORMAL
-
- 'did we advance or rollback to top ?
- IF Row% = NumRows% THEN
- 'when a col rollup occurs, the value of Selection%
- 'depends upon which col,we are currently in
- Selection% = 1 + ((Col% - 1) * NumRows%)
- 'we know that array ptr goes back to 1 on a col rollup
- Row% = 1
- ELSE
- Selection% = Selection% + 1
- Row% = Row% + 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** UP ARROW PRESSED ********************
-
- CASE IS = UPARROW
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- 'did we backup 1 or wrapdown to bot of list ?
- IF Row% = 1 THEN
- 'when a col wrapdown occurs, the value of Selection%
- 'is product of highest row # x col # we are now in
- Selection% = NumRows% * Col%
- 'we know that array ptr goes back to numrows on a col wrapdn
- Row% = NumRows%
- ELSE
- Selection% = Selection% - 1
- Row% = Row% - 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** LEFT ARROW PRESSED ******************
-
- CASE IS = LEFT
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- 'did we only backup 1 or wrap to right side of screen ?
- IF Col% = 1 THEN
- 'we wrapped to right side so col = largest col #
- Col% = NumCols%
- 'when a col wrap to right occurs, the value of
- 'Selection = row# + product of (# col - 1) * # rows
- Selection% = Row% + ((NumCols% - 1) * NumRows%)
- ELSE
- 'dec selection by # of items in a col
- 'and decrement col by 1
- Selection% = Selection% - NumRows%
- Col% = Col% - 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** RIGHT ARROW PRESSED ******************
-
- CASE IS = RIGHT
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- 'did we backup 1 or wrap to left side of screen ?
- IF Col% = NumCols% THEN
- 'since we wrapped to left side, col = 1 & row is same
- Col% = 1
- 'when a col wrapleft occurs, the value of Selection%
- 'is the same as the row # we are currently in
- Selection% = Row%
- ELSE
- Selection% = Selection% + NumRows%
- Col% = Col% + 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** HOME KEY PRESSED ******************
-
- CASE IS = HOME
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- Row% = 1
- Col% = 1
- Selection% = 1
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** END KEY PRESSED ******************
-
- CASE IS = ENDK
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- Row% = NumRows%
- Col% = NumCols%
- Selection% = (NumSelections%)
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** RIGHT TAB PRESSED ******************
-
- CASE IS = RIGHTAB
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- 'did we backup 1 or wrapleft to right side of screen ?
-
- IF Col% = NumCols% AND Row% <> NumRows% THEN
- 'we are wrapping to left side of screen but we are not
- 'at the bottom yet, so increment row
- Row% = Row% + 1
- Col% = 1
- Selection% = Row%
- ELSEIF Col% = NumCols% AND Row% = NumRows% THEN
- 'we were at the bottom right corner, so go to home pos
- Row% = 1
- Col% = 1
- Selection% = 1
- ELSE
- 'we are moving 1 to the right only, no wrapping, row same
- Selection% = Selection% + NumRows%
- Col% = Col% + 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- '**************** LEFT TAB PRESSED ******************
-
- CASE IS = LEFTAB
- 'un-highlight the old field
- NormRow% = Row% + RowOffSet%
- NormCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB NORMAL
-
- 'did we backup 1 or wrapleft to right side of screen ?
-
- IF Col% = 1 AND Row% <> 1 THEN
- 'we are wrapping to right side of screen but we are not
- 'at the top yet, so decrement row & reset col to right
- Row% = Row% - 1
- Col% = NumCols%
- 'back up selection #
- Selection% = Selection% + (((NumCols% - 1) * NumRows%) - 1)
-
- ELSEIF Col% = 1 AND Row% = 1 THEN
- 'we were at the top left corner, so go to end position
- Row% = NumRows%
- Col% = NumCols%
- Selection% = NumSelections%
- ELSE
- 'we are moving 1 to the left only, no wrapping, row is same
- Selection% = Selection% - NumRows%
- Col% = Col% - 1
- END IF
-
- 'highlight the next field
- HiLiteRow% = Row% + RowOffSet%
- HiLiteCol% = ((((Col% - 1) * ColWidth%) + StartCol%) + (Col% - 1) * ColSpace%)
- GOSUB HIGHLIGHT
-
- CASE ELSE
-
- IF Ky% <> ENTER THEN
- BEEP
- END IF
-
- END SELECT
-
- LOOP UNTIL Ky% = ENTER
-
- GOTO Bottom
-
- '----------------Normal & Highlight Routines-----------------
- NORMAL:
-
- 'return highlighted field to normal
- COLOR ForeNorm%, BackNorm%, 0
- LOCATE NormRow%, NormCol%, 0
- PRINT DispArray$(Selection%)
- RETURN
-
- HIGHLIGHT:
-
- 'highlight the new field
- COLOR ForeHi%, BackHi%, 0
- LOCATE HiLiteRow%, HiLiteCol%, 0
- PRINT DispArray$(Selection%)
- RETURN
- Bottom:
-
- 'Selection% now contains user choice
-
- END SUB
-
-